package com.dangdi.sip2;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

public class SocketClientAct {
    public int port;
    public String host;

    public SocketClientAct(String host, int port) {
        this.port = port;
        this.host = host;
    }

    public void sendMessage(String message) {
        try {
            Socket socket = new Socket(host, port);
            // 发送给服务器的数据
            DataOutputStream out = new DataOutputStream(socket.getOutputStream());
            out.writeUTF(message);
            // 接收服务器的返回数据
            DataInputStream in = new DataInputStream(socket.getInputStream());
            System.out.println("服务器说:" + in.readUTF());
            socket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        SocketClientAct clientAct = new SocketClientAct("192.168.1.11", 65535);
        clientAct.sendMessage("你好");
    }
}
